<template>
	<div class="user-avatar-dropdown">
		<Dropdown @on-click="handleClick">
			<!-- <Badge :dot="!!messageUnreadCount"> -->
			<Badge>
				<Avatar :src="userAvatar" />
			</Badge>
			<span style="padding: 0 5px">{{ userName }}</span>
			<Icon :size="18" type="md-arrow-dropdown" style="color:#ffffff"></Icon>
			<DropdownMenu slot="list">
				<!-- <DropdownItem name="setup">
					个人设置<Badge style="margin-left: 10px"></Badge>
				</DropdownItem> -->
				<DropdownItem name="logout">退出登录</DropdownItem>
			</DropdownMenu>
		</Dropdown>
	</div>
</template>

<script>
import './user.less'
import { mapActions } from 'vuex'
import avatar from '@/assets/images/head.png'
export default {
  name: 'User',
  props: {
    userName: {
      type: String,
      default: ''
    },
    userAvatar: {
      type: String,
      default: avatar
    },
    messageUnreadCount: {
      type: Number,
      default: 0
    }
  },
  methods: {
    ...mapActions(['handleLogOut']),
    logout () {
      this.handleLogOut().then(() => {
        location.reload()
      })
    },
    setup () {
      this.$router.push({
        name: 'setup_page'
      })
    },
    handleClick (name) {
      switch (name) {
        case 'logout':
          this.logout()
          break
        case 'setup':
          this.setup()
          break
      }
    }
  }
}
</script>
